<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <el-form :inline="true" :model="form" class="demo-form-inline">
        <el-form-item label="商家名称">
          <el-input
            v-model="form.company_name"
            placeholder="请输入商家名称"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="商品名称">
          <el-input v-model="form.name" placeholder="请输入商品名称"></el-input>
        </el-form-item> -->
        <el-form-item label="商家负责人">
          <el-input
            v-model="form.store_manager_name"
            placeholder="请输入商家负责人"
          ></el-input>
        </el-form-item>
        <el-form-item label="商家负责人电话">
          <el-input
            v-model="form.store_manager_phone"
            placeholder="请输入商家负责人电话"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="商品分类">
          <el-select
            v-model="form.type"
            placeholder="选择商品类型"
            @change="selectChange"
          >
            <el-option
              v-for="(item, index) in Data"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="时间">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            :default-time="['00:00:00', '23:59:59']"
            @change="timeChange"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="tableData"
        border
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          :index="Method"
          prop="id"
          width="90"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="logo"
          align="center"
          label="商家信息"
          width="320"
        >
          <template slot-scope="scope">
            <div class="modality">
              <el-image
                style="width: 70px; height: 70px; width: 20%"
                :src="imgHeader + scope.row.logo"
                class="leftImg"
              ></el-image>
              <div class="modalityUser">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.company_name"
                  placement="top-start"
                >
                  <span class="text"
                    >商家名称:{{ scope.row.company_name }}</span
                  >
                </el-tooltip>
                <!-- <el-tooltip
                  class="item"
                  effect="dark"
                  content=""
                  placement="top-start"
                >
                  <span class="text">店铺名称:</span>
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.seller_type_text"
                  placement="top-start"
                >
                  <span class="text"
                    >店铺类型:{{ scope.row.seller_type_text }}</span
                  >
                </el-tooltip> -->
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="store_manager_name"
          align="center"
          label="负责人"
        >
        </el-table-column>
        <el-table-column
          prop="store_manager_phone"
          align="center"
          label="负责人电话"
        >
        </el-table-column>
        <!-- <el-table-column align="center" label="水票图片">
          <template slot-scope="scope">
            <el-image
              style="width: 80px; height: 80px"
              :src="scope.row.water_img"
              fit="cover"
            ></el-image>
          </template>
        </el-table-column> -->
        <el-table-column prop="zan" align="center" label="商品点赞次数">
        </el-table-column>
        <el-table-column prop="cai" align="center" label="商品踩次数">
        </el-table-column>
        <!-- <el-table-column prop="amount" align="center" label="售卖总价">
        </el-table-column>
        <el-table-column prop="ctime" align="center" label="统计日期">
        </el-table-column> -->
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button @click="handleGo(scope.row)" size="mini" type="primary"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
    <el-dialog title="评价详情" :visible.sync="dialogTableVisible" width="60%">
      <div>
        <el-form :inline="true" :model="form" class="demo-form-inline">
          <el-form-item label="商品名称">
            <el-input
              v-model="form.goods_name"
              placeholder="请输入商品名称"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit1">查询</el-button>
            <el-button type="primary" @click="onReset1">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table :data="gridData" max-height="500" border>
        <el-table-column
          label="序号"
          type="index"
          :index="Method1"
          width="90"
          align="center"
        ></el-table-column>
        <el-table-column
          property="name"
          label="商品名称"
          align="center"
        ></el-table-column>
        <el-table-column label="商品规格" align="center">
          <template slot-scope="scope">
            长{{ scope.row.length }}，宽{{ scope.row.width }}，高{{
              scope.row.height
            }}
          </template>
        </el-table-column>
        <el-table-column
          property="sell_price"
          label="商品单价"
          align="center"
        ></el-table-column>
        <el-table-column
          property="zan"
          label="点赞次数"
          align="center"
        ></el-table-column>
        <el-table-column
          property="cai"
          label="踩次数"
          align="center"
        ></el-table-column>
      </el-table>
      <div class="pageUser">
        <el-pagination
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"
          :current-page="page1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total1"
        >
        </el-pagination>
      </div>
    </el-dialog>
  </el-card>
</template>

<script>
import {
  shouChuList,
  getReviews,
  getReviewsDetail,
} from "../../../../utils/main";
export default {
  data() {
    return {
      gridData: [],
      dialogTableVisible: false,
      imgHeader: this.Global.imgHeader,

      Data: [
        {
          name: "桶装水",
          id: "1",
        },
      ],
      token: sessionStorage.getItem("token"),
      //请求特效
      loading: false,
      //弹窗
      // dialogVisible: false,
      form: {
        company_name: "",
        store_manager_name: "",
        store_manager_phone: "",
      },
      time: "",
      //发送请求时间参数
      //展示数据
      tableData: [],
      store_manager_name: "",
      store_manager_phone: "",
      company_name: "",
      seller_id: "",
      goods_name: "",
      page: 1,
      limit1: 10,
      page1: 1,
      limit: 10,
      total: 0,
      total1: 0,
      name: "",
      type: "",
    };
  },
  methods: {
    //日期
    timeChange(e) {
      this.time = this.form.time;
      this.getList();
    },
    //查询
    onSubmit() {
      // console.log(this.form);
      this.store_manager_name = this.form.store_manager_name;
      this.store_manager_phone = this.form.store_manager_phone;
      this.company_name = this.form.company_name;
      this.page = 1;
      this.getList();
    },
    // 详情里根据商品名称查询
    onSubmit1() {
      // console.log(this.form);
      this.goods_name = this.form.goods_name;
      this.getListDetail();
    },
    // 重置
    onReset() {
      this.form.store_manager_name = "";
      this.form.store_manager_phone = "";
      this.form.company_name = "";
      this.store_manager_name = "";
      this.store_manager_phone = "";
      this.company_name = "";
      this.getList();
    },
    // 弹出层里的重置
    onReset1() {
      this.form.goods_name = "";
      this.goods_name = "";
      this.getListDetail();
    },
    //水票分类
    selectChange() {},
    //分页器
    handleSizeChange(val) {
      this.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getList();
    },
    handleSizeChange1(val) {
      this.limit1 = val;
      this.getListDetail();
    },
    handleCurrentChange1(val) {
      this.page1 = val;
      this.getListDetail();
    },
    // 序号排序
    Method(index) {
      if (this.token < this.limit) {
        return this.total - index;
      } else {
        return this.total - (this.page - 1) * this.limit - index;
      }
    },
    Method1(index) {
      if (this.token < this.limit1) {
        return this.total1 - index;
      } else {
        return this.total1 - (this.page1 - 1) * this.limit1 - index;
      }
    },
    // 获取商品评价列表
    async getList() {
      this.loading = true;
      let res = await getReviews(
        this.token,
        this.store_manager_name,
        this.store_manager_phone,
        this.company_name,
        this.limit,
        this.page
      );
      if (res.data.status) {
        this.tableData = res.data.data.list || [];
        this.total = res.data.data.count;
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    // 获取商品评价列表详情
    async getListDetail() {
      this.loading = true;
      let res = await getReviewsDetail(
        this.token,
        this.seller_id,
        this.goods_name,
        this.limit1,
        this.page1
      );
      if (res.data.status) {
        this.gridData = res.data.data.list || [];
        this.total1 = res.data.data.count;
        // console.log(this.total, shouchu);
        let timer = setTimeout(() => {
          this.loading = false;
          clearTimeout(timer);
        }, 400);
      } else {
        if (res.data.msg == "token失效,请重新进行登录") {
          this.$router.push("/login");
        }
        if (res.data.msg == "此账号没有权限") {
          this.$message.error(res.data.msg);
          this.loading = false;
        }
        let timer = setTimeout(() => {
          this.$message.error(res.data.msg);
        }, 5000);
      }
    },
    // 点击详情的事件
    async handleGo(row) {
      // console.log("id", row.goods_id);
      // let res = await fsfefwfef();
      // this.$router.push(`/stn/goodsdetail?goods_id=${row.goods_id}`);
      // console.log(this.$router);
      this.seller_id = row.seller_id;
      this.dialogTableVisible = true;
      this.getListDetail();
    },
    //关闭弹窗
    handleClose(done) {
      done();
      // this.packageCounts();
    },
  },
  mounted() {
    // this.sdhadj();
    this.getList();
  },
};
</script>

<style scoped>
.modality {
  display: flex;
  width: 100%;
}

.modality .leftImg {
  width: 20%;
}

.modalityUser {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 15px;
  width: 70%;
}

.modalityUser .item {
  display: block;
  text-align: left;
  width: 90%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>